home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / Algorithms / bubble.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-19  |  1.4 KB  |  50 lines

  1. #include<hold/anim.h>
  2.  
  3. /* 000 */ void bubble_control(void);
  4. /* 001 */ void bubble(int [], int);
  5.  
  6. /* 002 */ void bubble_control(){
  7. /* 003 */ int d[10] = {10,9,8,7,6,5,4,3,2,1};
  8. /* 004 */ int parts = 10;
  9.           a_func("bubble_control",2);
  10.           a_irayini(d,"d",parts,3);
  11.           a_intini(parts,"parts",4);
  12.           a_show(5);
  13.  
  14. /* 005 */   bubble(d,parts);
  15.             a_endfunc("bubble_control",6);
  16. /* 006 */ }
  17.  
  18. /* 007 */ void bubble(int a[], int N){
  19. /* 008 */ int i,j,t;
  20.  
  21.           a_func("bubble",7);
  22.           a_iraypas("a",7);
  23.           a_intini(N,"N",7);
  24.           a_intini(i,"i",8);
  25.           a_intini(j,"j",8);
  26.           a_intini(t,"t",8);
  27.           a_intass("i","N",9);
  28.           a_intcomp("i>=1",9);
  29. /* 009 */   for(i=N;i>=1;i--){
  30.               a_intass("j","1",10);
  31.               a_intcomp("j<i",10);
  32. /* 010 */     for(j=1;j<i;j++){
  33.                 a_intcomp("a[j-1] > a[j]",11);
  34. /* 011 */       if(a[j-1] > a[j]){
  35. /* 012 */         t = a[j-1];
  36.                   a_intass("t","a[j-1]",12);
  37. /* 013 */         a[j-1] = a[j];
  38.                   a_intass("a[j-1]","a[j]",13);
  39. /* 014 */         a[j] = t;
  40.                   a_intass("a[j]","t",14);
  41. /* 015 */       }
  42.                 a_intass("j","j+1",10);
  43.                 a_intcomp("j<i",10);
  44. /* 016 */     }
  45.               a_intass("i","i-1",9);
  46.               a_intcomp("i>=1",9);
  47. /* 017 */   }
  48.             a_endfunc("bubble",18);
  49. /* 018 */ }
  50.